package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.JarPackage;
import com.stylefeng.guns.modular.system.service.IJarPackageService;

/**
 * jar包管理控制器
 *
 * @author fengshuonan
 * @Date 2018-10-26 11:37:14
 */
@Controller
@RequestMapping("/jarPackage")
public class JarPackageController extends BaseController {

    private String PREFIX = "/system/jarPackage/";

    @Autowired
    private IJarPackageService jarPackageService;

    /**
     * 跳转到jar包管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "jarPackage.html";
    }

    /**
     * 跳转到添加jar包管理
     */
    @RequestMapping("/jarPackage_add")
    public String jarPackageAdd() {
        return PREFIX + "jarPackage_add.html";
    }

    /**
     * 跳转到修改jar包管理
     */
    @RequestMapping("/jarPackage_update/{jarPackageId}")
    public String jarPackageUpdate(@PathVariable Integer jarPackageId, Model model) {
        JarPackage jarPackage = jarPackageService.selectById(jarPackageId);
        model.addAttribute("item",jarPackage);
        LogObjectHolder.me().set(jarPackage);
        return PREFIX + "jarPackage_edit.html";
    }

    /**
     * 获取jar包管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return jarPackageService.selectList(null);
    }

    /**
     * 新增jar包管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(JarPackage jarPackage) {
        jarPackageService.insert(jarPackage);
        return SUCCESS_TIP;
    }

    /**
     * 删除jar包管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer jarPackageId) {
        jarPackageService.deleteById(jarPackageId);
        return SUCCESS_TIP;
    }

    /**
     * 修改jar包管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(JarPackage jarPackage) {
        jarPackageService.updateById(jarPackage);
        return SUCCESS_TIP;
    }

    /**
     * jar包管理详情
     */
    @RequestMapping(value = "/detail/{jarPackageId}")
    @ResponseBody
    public Object detail(@PathVariable("jarPackageId") Integer jarPackageId) {
        return jarPackageService.selectById(jarPackageId);
    }
}
